package com.shopcentre15.shopcentre.FormalShopExplot.Controller.Mchant;

import com.shopcentre15.shopcentre.FormalShopExplot.Entity.ShopMerchant;
import com.shopcentre15.shopcentre.FormalShopExplot.Service.Mchant.MchantService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/mchant_func")
public class MchantController {
    @Autowired
    private MchantService mchantService;
    @PostMapping("/mchant_login")
    @ResponseBody
    public ResponseEntity<?> mchantLogin(@RequestParam("account") String account, @RequestParam("password") String password) {
        try {
            if (account == null || password == null) {
                return ResponseEntity.badRequest().body("用户名和密码不能为空");
            }
            ShopMerchant shopMerchant = mchantService.mchantLogin(account, password);
            if (shopMerchant == null) {
                return ResponseEntity.badRequest().body("账户或密码错误");
            }
            return ResponseEntity.ok(shopMerchant);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return ResponseEntity.badRequest().body("登录失败，请重试");
        }
    }
}
